/* 
 * Project: FlarDetector
 *
 * Copyright 2009, Longfellow Chen
 * --------------------------------------------------------------------------------
 * This work complements FLARToolkit, developed by Saqoosha as part of the Libspark project.
 *	http://www.libspark.org/wiki/saqoosha/FLARToolKit
 * FLARToolkit is Copyright (C)2008 Saqoosha,
 * and is ported from NYARToolkit, which is ported from ARToolkit.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this framework; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * For further information please contact:
 *	<fellong0307@gmail.com>
 *	http://fellong.blogspot.com/
 * 
 */
 
package com.fellong.flash.flar.object
{
	import com.fellong.flash.flar.detector.FlarDetector;
	
	import flash.events.Event;
	
	import org.libspark.flartoolkit.support.pv3d.FLARBaseNode;
	import org.papervision3d.objects.DisplayObject3D;
	
	public class FlarObject extends FLARBaseNode
	{
		protected var _pivot:DisplayObject3D;	/// 保有一個object讓外部操作而不被flar運算影響的相對物件
		protected var _detector:FlarDetector;
				
		public function FlarObject()
		{
			super();
			
			_detector = new FlarDetector();
			_pivot = new DisplayObject3D();
			this.addChild( _pivot, "axis" );
			_pivot.rotationX = 90;
			_pivot.rotationZ = 90;
			_detector.addEventListener( FlarDetector.MARKER_ADDED, onMARKER_ADDED );
			_detector.addEventListener( FlarDetector.MARKER_UPDATED, onMARKER_UPDATED );
			_detector.addEventListener( FlarDetector.MARKER_REMOVED, onMARKER_REMOVED );
			this.visible = false;
		}
		
		protected function onMARKER_ADDED( event:Event ):void
		{
		}
		
		protected function onMARKER_UPDATED( event:Event ):void
		{
			this.setTransformMatrix( this.detector.transmat );
			this.visible = true;
		}
		
		protected function onMARKER_REMOVED( event:Event ):void
		{
			this.visible = false;
		}

		public function get pivot():DisplayObject3D
		{
			return _pivot;
		}
		
		public function get detector():FlarDetector
		{
			return _detector;
		}
		
		public function set confidence( v:Number ):void
		{
			_detector._confidence = v;
		}
		
		public function set delay( v:Number ):void
		{
			_detector._delay = v;
		}
		
		public function set smooth( v:Number ):void
		{
			_detector._smooth = v;
		}
		
	}
}